<template>
  <div>
  <el-drawer title="修改角色" :visible.sync="dialogFormVisible" size="25%">
      <el-form :inline="true" ref="formInline" :model="formInline" :rules="rules" :label-position="labelPosition" style="width: 120%" label-width="105px" class="demo-form-inline" size="small">
        <el-row>
          <el-col :span="24">
            <el-form-item label="角色名称:" prop="name">
              <el-input v-model="formInline.name" :style="{width: '140%'}" placeholder="请输入角色名称"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="权限字符:" prop="key">
              <el-input v-model="formInline.key" :style="{width: '140%'}" placeholder="请输入权限字符"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="排序:" prop="sort">
              <el-input-number size="medium" :min="0" :max="999" v-model="formInline.sort"></el-input-number>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="是否管理员:" prop="admin">
              <el-radio-group v-model="formInline.admin">
                <el-radio :label="true">是</el-radio>
                <el-radio :label="false">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="状态:" prop="status">
              <el-radio-group v-model="formInline.status">
                <el-radio :label="true">是</el-radio>
                <el-radio :label="false">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>



        <el-row>
          <el-col :span="24">
            <el-form-item label="备注:" prop="remark">
              <el-input style='width: 130%' maxlength="125" show-word-limit type="textarea" v-model="formInline.remark"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
    <div class="demo-drawer__footer" style="padding-left: 100px;">
      <el-button @click="resetForm('formInline')">取 消</el-button>
      <el-button type="primary" @click="submitEditForm('formInline')">修 改</el-button>
    </div>
  </el-drawer>
  </div>
</template>

<script>
  import { editRoleData } from '@/api/role'
  import { successMsg,errmsg } from '@/utils/tools'
  export default {
    name: 'Edit',
    data() {
      return {
        dialogFormVisible: false,
        labelPosition:'right',
        formInline: {
          // parent: '',
          // name: '',
          // owner:'',
          // phone:'',
          // email:'',
          // status:true,
          // sort:0
        },
        rules:{
          name:[
            { required: true, message: '请输入角色名称', trigger: 'blur' },
          ],
          key:[
            { required: true, message: '请输入权限标识', trigger: 'blur' },
          ],
        }
      };
    },
    methods:{
      submitEditForm(formName) {
        this.$refs[formName].validate((valid) => {
          if(valid){
            editRoleData(this.formInline).then(res=>{
              if(res.code===2000) {
                successMsg(res.msg)
                this.$emit('reloadTable')
                this.dialogFormVisible = false
              }
            }).catch(()=>{})
          }else{
            return false;
          }
        });
      },
      resetForm(formName){
        this.$refs[formName].resetFields();
        this.dialogFormVisible = false
      },
    }
  }
</script>

<style>
  .main-select-el-tree .el-tree-node .is-current > .el-tree-node__content{font-weight: bold; color: #409eff;}
  .main-select-el-tree .el-tree-node.is-current > .el-tree-node__content{font-weight: bold; color: #409eff;}
</style>
